<?php
/**
 * Created by PhpStorm.
 * User: zhengze
 * Date: 2019/7/1
 * Time: 18:29
 */

namespace app\api\controller;

use app\api\service\RecordService;
use app\api\validate\RecordValidate;
use app\api\model\Record as RecordModel;
use common\controller\TokenController;


/**
 * Class Record
 * @package app\api\controller\v1
 */
class Record extends TokenController
{

    /**
     * 返回一个代表成功的json数据 <br>['code' => 0, 'msg' => 'success', 'data' => $data]
     * @param array $data
     * @param array $param
     * @return \think\response\Json
     */
    public function json_responce($data = [], $param = [])
    {
        return parent::json_responce($data, $param);
    }

    protected function initialize()
    {
        parent::initialize();
    }

    /**
     * @return \think\response\Json
     */
    public function getRecordList()
    {
        $input_rulr = [
            'exe_date' => '',
            'page' => '1',
            'limit' => '20',
        ];
        $get = input_extract_rule($input_rulr, 'get');
        $ret = RecordService::instance()->getRecordList($get);
        $get['type_map'] = RecordModel::$type_map;
        return $this->json_responce($ret, $get);
    }

    /**
     * @return \think\response\Json
     */
    public function viewRecord()
    {
        $input_rulr = [
            'record_id' => '',
        ];
        $get = input_extract_rule($input_rulr, 'get');
        $ret = RecordService::instance()->viewRecord($get);
        $get['type_map'] = RecordModel::$type_map;
        $data = ['info' => $ret];
        return $this->json_responce($data, $get);
    }

    /**
     * @return \think\response\Json
     */
    public function save()
    {
        $input_rulr = [
            'type' => '',
            'content' => '',
            'exe_date' => '',
        ];
        $post = input_extract_rule($input_rulr, 'post');
        RecordValidate::instance()->runCheck($post, '', __FUNCTION__);
        $ret = RecordService::instance()->save($post);
        return $this->json_responce(null);
    }
}
